<template>
	<view class="page">

		<view class="page-content " style="padding-bottom: 150rpx;">
			<view class="p12 pt20">
				<view @click="edit(item)" class="mb25 u-flex u-f-jsb u-f-justify" v-for="(item,index) in list" :key="index">
					<view class="u-flex">
						<image src="../../../static/image/ad3.png" class="w50 h50" style="min-width: 100rpx;"></image>
					<view class="pl10 pr10">
						<view class="u-flex fz15 u-font-bold">
							{{item.name}}<span class="fz13 ml8">{{item.mobile}}</span>
						</view>
						
						<view class="u-flex fz12 mt4">
						{{item.areaName}} {{item.detailAddress}}
						</view>
					</view>
					</view>
					
					<view @click.stop="toEdit(item)">
						<image src="../../../static/image/ad1.png" class="w20 h20"></image>
					</view>
				</view>
			</view>
		</view>

		<view class="fixed-bottom module-btn">
			<button type="primary" @click="add"
				style="background: #70B52C;" class="btn">添加收货地址</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				sysInfo:getApp().globalData.sysInfo,
				source:'',
				list:[]
			}
		},
		onShow() {
			this.getList();
		},
		onLoad(e){
			if(e.source){
				this.source=e.source
			}
		},
		methods: {
			setAddress:function(obj){
				var that=this;
				wx.setStorage({
					key:'selectedAddress',
					data:JSON.stringify(obj),
					success:function(){
						if(getCurrentPages().length>1){
							wx.navigateBack({
								delta:1
							})
						}	
					}
				});
			},
			add:function(){
				uni.navigateTo({
					url:"/pages/user/address/add"
				})
			},
			edit:function(item){
				if(this.source=='order'){
					this.setAddress(item)
					return
				}
				uni.navigateTo({
					url:"/pages/user/address/add?id="+item.id
				})
			},
			toEdit:function(item){
				uni.navigateTo({
					url:"/pages/user/address/add?id="+item.id
				})
			},
			getList:function(){
				this.$api.addressList({}, res => {
					if (res.code == 200) {
						this.list=res.data
					} else {
				
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				});
				
			}
		},
		mounted() {
			
		}
	}
</script>

<style lang="scss">
	.module-btn {
		.btn {
			border-radius: 16rpx;
		}
	}
</style>